﻿#include <iostream>
#include "MySuperLinkList.h"
using namespace std;
#define PARAMETER 15
template <class T>
int meld(MySuperLinkList<T>& list1, MySuperLinkList<T>& list2, MySuperLinkList<T>& list);
int main() {
	MySuperLinkList<int> list1, list2,list3;
	for (int i = 0; i < PARAMETER; i++) {
		list1.push_back(i);
	}
	for (int i = 5; i < PARAMETER; i++)
		list2.push_back(2 * i - 3);
	cout << "list1:" << list1;
	cout << "list2:" << list2;
	cout << "----------------------------------------------------" << endl;
	cout <<"进入循环：" <<meld(list1, list2, list3) <<"次。" << '\n';
	cout << "list3:" << list3;
	return 0;
}



template <class T>
int meld(MySuperLinkList<T>& list1, MySuperLinkList<T>& list2,MySuperLinkList<T>& list) {          //必须引用传值
	if (list1.isEmpty() || list2.isEmpty()) {
		(list1.isEmpty()) ? list=list2 : list=list1;
		return 1;
	}
	int count = 1;
	while (!list1.isEmpty() && !list2.isEmpty()) {
		if (count % 2 == 1) {
			list.push_back(list1.get(1));
			list1.erase(1);
			count++;
		}
		else {
			list.push_back(list2.get(1));
			list2.erase(1);
			count++;
		}
	}
	while (!list1.isEmpty()) {
		list.push_back(list1.get(1));
		list1.erase(1);
		count++;
	}
	while (!list2.isEmpty()) {
		list.push_back(list2.get(1));
		list2.erase(1);
		count++;
	}
	return count;
}
